package com.ideal.manage.esms.repository.project;

import com.ideal.manage.esms.bean.project.ProjectManage;
import com.ideal.manage.esms.repository.framework.BaseRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created By Dai On 2018/4/24
 * Remark: 工程配置-项目管理 Repository
 */
public interface ProjectManageRepository extends BaseRepository<ProjectManage, String> {

    @Query("select p from ProjectManage p where p.isValid=1 ")
    List<ProjectManage> findAllManages();

    @Query("select p from ProjectManage p where p.id=?1 and p.isValid=1")
    ProjectManage findByEquipmentId(String equipmentId);

    /**
     * 根据项目名找到项目
     *
     * @param name
     * @return
     */
    @Query("select p from ProjectManage p where p.name=?1 and p.isValid=1")
    ProjectManage findByName(String name);

    @Query("select p from ProjectManage p where p.isValid=1")
    List<ProjectManage> findAllProjects();

    /**
     * 找到所有未删除的项目
     *
     * @return
     */
    @Query("select count(p.id) from  ProjectManage p where p.isValid=1 ")
    Long findCount();

    /**
     * 找到所有未删除 状态值等于指定值的项目
     *
     * @return
     */
    @Query("select count(p.id) from  ProjectManage p where p.isValid=1 and p.status=?1")
    Long findCountByStatus(int status);

    @Query("select p from ProjectManage p where p.isValid=1")
    List<ProjectManage> findByAllIp();

    @Query("select p.ip from ProjectManage p where p.isValid=1 and p.status=1")
    List<String> findByPip();

}
